package im.yisme.model.game;

public class ScoringSystem {

	private int score;
	private int combo;
	private int maxCombo;
	private float averageAccuracy;
	private int noteNum;
	
	private static final int VALID_HIT=100;
	private static final int VALID_MOVE=10;
	
	public ScoringSystem(){
		reset();
	}
	public void reset(){
		score=0;
		combo=0;
		maxCombo=0;
		averageAccuracy=0;
		noteNum=0;
	}
	public int getScore(){
		return score;
	}
	public int getCombo(){
		return combo;
	}
	public int getMaxCombo(){
		return maxCombo;
	}
	public float getAverageAccuracy(){
		return averageAccuracy;
	}
	public void addValidHit(float accuracy){
		score=score+(int)(VALID_HIT*accuracy);
		averageAccuracy = (averageAccuracy*noteNum+accuracy)/(noteNum+1);
		noteNum++;
		comboUp();
	}
	public void addValidMove(){
		score=score+VALID_MOVE;
	}
    public void InvalidAction(){
    	averageAccuracy = (averageAccuracy*noteNum)/(noteNum+1);
		noteNum++;
    	combo=0;
    }
    
    private void comboUp(){
    	combo++;
    	if(combo>maxCombo) maxCombo=combo;
    }
    
    public String getLevel(){
    	
    	if(maxCombo>noteNum*0.9 && averageAccuracy>0.9) return "S";
    	else if(maxCombo > noteNum*0.8 && averageAccuracy>0.8) return "A";
    	else if(maxCombo > noteNum*0.7 && averageAccuracy>0.7) return "B";
    	else if(maxCombo > noteNum*0.6 && averageAccuracy>0.6) return "C";
    	else if(maxCombo > noteNum*0.5 && averageAccuracy>0.5) return "D";
    	else if(maxCombo > noteNum*0.4 && averageAccuracy>0.4) return "E";
    	else return "F";
    }
}
